create or replace package DM_KHO_MA_THE_GOC_P is

  -- Author  : TINHTH
  -- Created : 7/5/2012 2:41:02 PM
  -- Purpose : Quan ly kho ma the goc
/*Tao ngau nhien ma kho the goc
|| 20tr: 1 thang
|| 30tr: 3 thang
|| 30tr: 6 thang
|| 20tr: 12 thang
*/
procedure gen_dm_kho_ma_the_goc;
/*
|| Cap nhat trang thai the khi mang di in
*/
procedure update_ma_the_goc_da_in(ip_id in DM_KHO_MA_THE_GOC.ID%TYPE);
end DM_KHO_MA_THE_GOC_P;
/
create or replace package body DM_KHO_MA_THE_GOC_P is

  -- Author  : TINHTH
  -- Created : 7/5/2012 2:41:02 PM
  -- Purpose : Quan ly kho ma the goc
/*Tao ngau nhien ma kho the goc
|| 20tr: 1 thang
|| 30tr: 3 thang
|| 30tr: 6 thang
|| 20tr: 12 thang
*/
procedure gen_dm_kho_ma_the_goc is
v_int_max number := 1;
begin
--
     while (v_int_max <=20000000)
     loop
         insert into dm_kho_ma_the_goc(id,ma_the_in_kich_hoat,loai_thoi_han,da_in_yn,loai_the)
                values(v_int_max,substr(dbms_random.value(10000000000000, 99999999999999),0,14)
                                                                          ,constants_p.C_THE_1_THANG
                                                                          ,'N'
                                                                          ,constants_p.C_LOAI_THE_THUONG);
         v_int_max := v_int_max + 1;
     end loop;
--
     while (v_int_max <=50000000)
     loop
         insert into dm_kho_ma_the_goc(id,ma_the_in_kich_hoat,loai_thoi_han,da_in_yn,loai_the)
                values(v_int_max,substr(dbms_random.value(10000000000000, 99999999999999),0,14)
                                                                          ,constants_p.C_THE_3_THANG
                                                                          ,'N'
                                                                          ,constants_p.C_LOAI_THE_THUONG);
         v_int_max := v_int_max + 1;
     end loop;
--
     while (v_int_max <=80000000)
     loop
         insert into dm_kho_ma_the_goc(id,ma_the_in_kich_hoat,loai_thoi_han,da_in_yn,loai_the)
                values(v_int_max,substr(dbms_random.value(10000000000000, 99999999999999),0,14)
                                                                          ,constants_p.C_THE_6_THANG
                                                                          ,'N'
                                                                          ,constants_p.C_LOAI_THE_THUONG);
         v_int_max := v_int_max + 1;
     end loop;
--
     while (v_int_max <=100000000)
     loop
         insert into dm_kho_ma_the_goc(id,ma_the_in_kich_hoat,loai_thoi_han,da_in_yn,loai_the)
                values(v_int_max,substr(dbms_random.value(10000000000000, 99999999999999),0,14)
                                                                          ,constants_p.C_THE_12_THANG
                                                                          ,'N'
                                                                          ,constants_p.C_LOAI_THE_THUONG);
         v_int_max := v_int_max + 1;
     end loop;
end gen_dm_kho_ma_the_goc;
/*
|| Cap nhat trang thai the khi mang di in
*/
procedure update_ma_the_goc_da_in(ip_id in DM_KHO_MA_THE_GOC.ID%TYPE)
is
begin
     update dm_kho_ma_the_goc g
     set g.da_in_yn = 'Y'
     where g.id = ip_id;
end update_ma_the_goc_da_in;
end DM_KHO_MA_THE_GOC_P;
/
